#include "syscall.h"

int myexp(int count) {
    int i, val = 1;
    for (i = 0; i < count; i++) {
        val = val * 10;
    }
    return val;
}

char* itoa(int val) {
    char strInt[10] ;
    int i, max, dig, subval, loc;
    for (i = 0; i < 10; i++) {
        strInt[i] = '\0';
    }
    for (i = 1; i <= 2; i++) {
        if ((val / myexp(i)) == 0) {
            max = i - 1;
            break;
        }
    }
    subval = 0;
    loc = 0;
    for (i = max; i >= 0; i--) {
        dig = 48 + ((val - subval) / myexp(i));
        subval = (dig - 48) * myexp(max);
        strInt[loc] = dig;
        loc++;
    }
    return strInt;
}

int strLen(char* str) {
    int i = 0;
    for (i = 0;; i++) {
        if (str[i] == '\0')
            break;
    }
    return i;
}

char* strCat(char* first, char* second) {

    int len1 = strLen(first);
	int len2 = strLen(second);
	int i;
    char newStr[len1 + len2 + 1];

    for (i = 0; i < len1; i++) {
        newStr[i] = first[i];
    }

    for (i = 0; i < len2; i++) {
        newStr[len1 + i] = second[i];
    }

    newStr[len1 + len2 + 1] = '\0';
    return newStr;
}

int main() {
    char* buf = "This is test string:\0";
    int  ind = 24 ;
    char* buf2 = strCat("\n\0", itoa(ind)) ;

    Write(buf, strLen(buf), ConsoleOutput);
    Write(buf2, strLen(buf2), ConsoleOutput);
}
